#include "IRender.h"

struct BackgroundRender : IRender
{
	BackgroundRender(const dxres& res) :
		IRender(res)
	{
	}

	void Render() override
	{
		D2D1_SIZE_F size = m_res.target->GetSize();
		D2D1_RECT_F rect = RectF(0.0f, 0.0f, 
								 size.width, size.height);

		m_res.target->FillRectangle(rect, m_brush.Get());
	}

	void CreateDeviceSizeResources(float width, float height) override
	{
		D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES properties = LinearGradientBrushProperties(
			Point2F(),
			Point2F(width, height));

		D2D1_GRADIENT_STOP stops[] = 
		{
			GradientStop(0.0f, ColorF(ColorF::Gray)), 
			GradientStop(1.0f, ColorF(ColorF::Black))
		};

		ComPtr<ID2D1GradientStopCollection> collection;
		HR(m_res.target->CreateGradientStopCollection(stops, 
													  _countof(stops), 
													  collection.GetAddressOf()));

		HR(m_res.target->CreateLinearGradientBrush(properties, 
												   collection.Get(), 
												   m_brush.GetAddressOf()));
	}

	void ReleaseDeviceSizeResources() override
	{
		m_brush.Reset();
	}

	ComPtr<ID2D1LinearGradientBrush> m_brush;
};